// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    plans:[]
  },
  onLoad() {
    var that = this;
    var user = wx.getStorageSync('user');
    var token = wx.getStorageSync('token');
    wx.request({
      url: 'http://127.0.0.1:8080/system/userPlan/list?userId='+user.userId, // 获取每日计划接口
      method: 'GET',
      header: {
        'content-type': 'application/json',  //这里注意POST请求content-type是小写，大写会报错  
        'Authorization': token
      },
      success(res) {
        if (res.data.code==200) {
          that.setData({
            plans : res.data.rows
          })
        } else {
          wx.showToast({
            title: "初始化计划失败",
            icon: 'none',
          })
        }
      }
    })
  },
  deletePlan(option){
    var that = this;
    var token = wx.getStorageSync('token');
    wx.request({
      url: 'http://127.0.0.1:8080/system/userPlan/'+option.currentTarget.dataset.test, // 删除计划接口
      method: 'delete',
      header: {
        'content-type': 'application/json',  //这里注意POST请求content-type是小写，大写会报错  
        'Authorization': token
      },
      success(res) {
        if (res.data.code==200) {
          that.onLoad()
        } else {
          wx.showToast({
            title: "删除计划失败",
            icon: 'none',
          })
        }
      }
    })
  }
})
